﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.AlbLab.GEP.Dao.Base;
using Com.AlbLab.GEP.Dao.Interface;
using Com.AlbLab.GEP.Domain.Entities;
using Oracle.DataAccess.Client;
using Com.AlbLab.GEP.Domain;
using System.Data;

namespace Com.AlbLab.GEP.Dao.Impl
{
    public class PraticaDao : OracleDao<OracleSessionManager, ISessionModel>, IPraticaDao
    {
        const int STATO_InLavorazione = 15;
        const int STATO_chiuso = 20;
        const int STATO_inviata = 25;

        public PraticaDao(OracleSessionManager daoContext)
            : base(daoContext)
        {
            if (!base.Context.Session_isActive())
            {
                base.Context.Session_Init();
                base.CurrentConnection.Open();
            }
        }

        private string seletctAll = "select * from GEP_TESTATA";
        //private string selectRicerca = "select TES_COD_PRATICA,TES_COD_SERVIZIO,TES_COD_CONTR_DISP,TES_DT_ARR_PRA,TES_CODFIS_CLI,TES_PARIVA_CLI,TES_RAGSOC_CLI,TES_COD_PRAT_UTENTE,TES_POD, TES_STATO from GEP_TESTATA";
        private string selectRicerca = "Select f.* FROM ("
                                     + "select a.TES_COD_PRATICA,a.TES_COD_SERVIZIO,a.TES_COD_CONTR_DISP,a.TES_DT_ARR_PRA,a.TES_DT_INS_PRA,a.TES_CODFIS_CLI,a.TES_PARIVA_CLI,a.TES_RAGSOC_CLI,a.TES_COD_PRAT_UTENTE,a.TES_POD, a.TES_STATO,  "
                                     + "NVL((select max(fas_progr_fase) from GEP_FASE b where a.tes_cod_pratica=b.FAS_COD_PRATICA),-1) ultima_fase,"
                                     + "NVL(( select FAS_UNIT_OPER from GEP_FASE b where a.tes_cod_pratica=b.FAS_COD_PRATICA "
                                     + "                                        and b.fas_progr_fase = (select MAX(FAS_PROGR_FASE) from GEP_FASE c "
                                     + "                                                                                           where c.fas_cod_pratica=b.fas_cod_pratica)),-1) fas_unit_oper, "
                                     + "NVL(( select upper(FAS_DES_FASE)||' / '||lower(STF_DES_STATO) from GEP_FASE b,gep_ana_statof c1 where b.fas_stato=c1.STF_COD_STATO"
                                      + " AND a.tes_cod_pratica=b.FAS_COD_PRATICA "
                                     + "                                        and b.fas_progr_fase = (select MAX(FAS_PROGR_FASE) from GEP_FASE d "
                                     + "                                                                                           where d.fas_cod_pratica=b.fas_cod_pratica)),'') fas_des_fase "
                                     + "from gep_testata a) f";

        private string selectById = "select GEP_RISPOSTE.RESP_XML,GEP_TESTATA.*  from GEP_TESTATA LEFT OUTER JOIN GEP_RISPOSTE ON GEP_TESTATA.TES_COD_PRATICA= GEP_RISPOSTE.RESP_ID_REQ WHERE TES_COD_PRATICA=:TES_COD_PRATICA";
        private string delete = "delete GEP_TESTATA WHERE TES_COD_PRATICA=:TES_COD_PRATICA";
        
        private string update = "UPDATE GEP_TESTATA"
                              + " SET TES_STATO = :TES_STATO, TES_COD_SERVIZIO = :TES_COD_SERVIZIO, TES_PIVA_UTENTE = :TES_PIVA_UTENTE,"
                              + " TES_PIVA_DISTRIBUTORE = :TES_PIVA_DISTRIBUTORE, TES_COD_PRAT_UTENTE = :TES_COD_PRAT_UTENTE,"
                              + " TES_COD_CONTR_DISP = :TES_COD_CONTR_DISP, TES_POD = :TES_POD, TES_CODFIS_CLI = :TES_CODFIS_CLI, TES_PARIVA_CLI = :TES_PARIVA_CLI,"
                              + " TES_COD_PRES = :TES_COD_PRES, TES_TEL_CLI = :TES_TEL_CLI, TES_FILENAME_RIC = :TES_FILENAME_RIC, TES_DT_ARR_PRA = :TES_DT_ARR_PRA, TES_DT_INS_PRA = :TES_DT_INS_PRA,"
                              + " TES_DES_PRA = :TES_DES_PRA, TES_RAGSOC_UTE = :TES_RAGSOC_UTE, TES_RAGSOC_CLI = :TES_RAGSOC_CLI, TES_IND_CLI = :TES_IND_CLI,"
                              + " TES_IND_FORNIT = :TES_IND_FORNIT, TES_COD_CONTR_CLI = :TES_COD_CONTR_CLI, TES_MIS_ELECO = :TES_MIS_ELECO, TES_MATR_ATT = :TES_MATR_ATT,"
                              + " TES_MATR_REA = :TES_MATR_REA, TES_MATR_POT = :TES_MATR_POT, TES_TENSIONE = :TES_TENSIONE, TES_POTENZA_CONTR = :TES_POTENZA_CONTR,"
                              + " TES_POTENZA_TOLL = :TES_POTENZA_TOLL, TES_FASI = :TES_FASI, TES_USO = :TES_USO, TES_K = :TES_K, TES_NOTE = :TES_NOTE,TES_DT_CHI_PRA = :TES_DT_CHI_PRA, TES_DT_INV_PRA = :TES_DT_INV_PRA"
                              + " WHERE (TES_COD_PRATICA = :TES_COD_PRATICA)";
        
        private string insert = "INSERT INTO GEP_TESTATA"
                              + " (TES_COD_PRATICA,TES_STATO, TES_COD_SERVIZIO, TES_PIVA_UTENTE, TES_PIVA_DISTRIBUTORE, TES_COD_PRAT_UTENTE, TES_COD_CONTR_DISP, TES_POD,"
                              + " TES_CODFIS_CLI, TES_PARIVA_CLI, TES_COD_PRES, TES_TEL_CLI, TES_FILENAME_RIC, TES_DT_ARR_PRA, TES_DT_INS_PRA, TES_DES_PRA, TES_RAGSOC_UTE," 
                              + " TES_RAGSOC_CLI, TES_IND_CLI, TES_IND_FORNIT, TES_COD_CONTR_CLI, TES_MIS_ELECO, TES_MATR_ATT, TES_MATR_REA, TES_MATR_POT, TES_TENSIONE,"
                              + " TES_POTENZA_CONTR, TES_POTENZA_TOLL, TES_FASI, TES_USO, TES_K, TES_NOTE,TES_DT_CHI_PRA, TES_DT_INV_PRA)"
                              + " VALUES(ASM_GEP_TESTATA_ID.NEXTVAL, :TES_STATO,:TES_COD_SERVIZIO, :TES_PIVA_UTENTE, :TES_PIVA_DISTRIBUTORE, :TES_COD_PRAT_UTENTE, :TES_COD_CONTR_DISP, :TES_POD,"
                              + " :TES_CODFIS_CLI, :TES_PARIVA_CLI, :TES_COD_PRES, :TES_TEL_CLI, :TES_FILENAME_RIC, :TES_DT_ARR_PRA, :TES_DT_INS_PRA, :TES_DES_PRA, :TES_RAGSOC_UTE," 
                              + " :TES_RAGSOC_CLI, :TES_IND_CLI, :TES_IND_FORNIT, :TES_COD_CONTR_CLI, :TES_MIS_ELECO, :TES_MATR_ATT, :TES_MATR_REA, :TES_MATR_POT,"
                              + " :TES_TENSIONE, :TES_POTENZA_CONTR, :TES_POTENZA_TOLL, :TES_FASI, :TES_USO, :TES_K, :TES_NOTE, :TES_DT_CHI_PRA, :TES_DT_INV_PRA)"
                              + " RETURNING TES_COD_PRATICA INTO :TES_COD_PRATICA";

        private OracleParameter[] MappingParams(GEP_TESTATA r, bool isInsert)
        {
            OracleParameter[] oparams;
            oparams = new OracleParameter[34];
            oparams[0] = new OracleParameter("TES_STATO", OracleDbType.Decimal, r.Tes_Stato, ParameterDirection.Input); 
            oparams[1] = new OracleParameter("TES_COD_SERVIZIO", OracleDbType.Varchar2, r.Tes_Cod_Servizio, ParameterDirection.Input); 
            oparams[2] = new OracleParameter("TES_PIVA_UTENTE", OracleDbType.Varchar2, r.Tes_Piva_Utente, ParameterDirection.Input); 
            oparams[3] = new OracleParameter("TES_PIVA_DISTRIBUTORE", OracleDbType.Varchar2, r.Tes_Piva_Distributore, ParameterDirection.Input); 
            oparams[4] = new OracleParameter("TES_COD_PRAT_UTENTE", OracleDbType.Varchar2, r.Tes_Cod_Prat_Utente, ParameterDirection.Input); 
            oparams[5] = new OracleParameter("TES_COD_CONTR_DISP", OracleDbType.Varchar2, r.Tes_Cod_Contr_Disp, ParameterDirection.Input); 
            oparams[6] = new OracleParameter("TES_POD", OracleDbType.Varchar2, r.Tes_Pod, ParameterDirection.Input);
            oparams[7] = new OracleParameter("TES_CODFIS_CLI", OracleDbType.Varchar2, r.Tes_Codfis_Cli, ParameterDirection.Input); 
            oparams[8] = new OracleParameter("TES_PARIVA_CLI", OracleDbType.Varchar2, r.Tes_Pariva_Cli, ParameterDirection.Input); 
            oparams[9] = new OracleParameter("TES_COD_PRES", OracleDbType.Varchar2, r.Tes_Cod_Pres, ParameterDirection.Input); 
            oparams[10] = new OracleParameter("TES_TEL_CLI", OracleDbType.Varchar2, r.Tes_Tel_Cli, ParameterDirection.Input); 
            oparams[11] = new OracleParameter("TES_FILENAME_RIC", OracleDbType.Varchar2, r.Tes_Filename_Ric, ParameterDirection.Input); 
            oparams[12] = new OracleParameter("TES_DT_ARR_PRA", OracleDbType.TimeStamp, r.Tes_Dt_Arr_Pra, ParameterDirection.Input);
            oparams[13] = new OracleParameter("TES_DT_INS_PRA", OracleDbType.TimeStamp, r.Tes_Dt_Ins_Pra, ParameterDirection.Input); 
            oparams[14] = new OracleParameter("TES_DES_PRA", OracleDbType.Varchar2, r.Tes_Des_Pra, ParameterDirection.Input);
            oparams[15] = new OracleParameter("TES_RAGSOC_UTE", OracleDbType.Varchar2, r.Tes_DBA_Ragsoc_Ute, ParameterDirection.Input);
            oparams[16] = new OracleParameter("TES_RAGSOC_CLI", OracleDbType.Varchar2, r.Tes_DBA_Ragsoc_Cli, ParameterDirection.Input);
            oparams[17] = new OracleParameter("TES_IND_CLI", OracleDbType.Varchar2, r.Tes_DBA_Ind_Cli, ParameterDirection.Input);
            oparams[18] = new OracleParameter("TES_IND_FORNIT", OracleDbType.Varchar2, r.Tes_DBA_Ind_Fornit, ParameterDirection.Input);
            oparams[19] = new OracleParameter("TES_COD_CONTR_CLI", OracleDbType.Varchar2, r.Tes_DBA_Cod_Contr_Cli, ParameterDirection.Input);
            oparams[20] = new OracleParameter("TES_MIS_ELECO", OracleDbType.Varchar2, r.Tes_DBA_Mis_Eleco, ParameterDirection.Input);
            oparams[21] = new OracleParameter("TES_MATR_ATT", OracleDbType.Varchar2, r.Tes_DBA_Matr_Att, ParameterDirection.Input);
            oparams[22] = new OracleParameter("TES_MATR_REA", OracleDbType.Varchar2, r.Tes_DBA_Matr_Rea, ParameterDirection.Input);
            oparams[23] = new OracleParameter("TES_MATR_POT", OracleDbType.Varchar2, r.Tes_DBA_Matr_Pot, ParameterDirection.Input);
            oparams[24] = new OracleParameter("TES_TENSIONE", OracleDbType.Varchar2, r.Tes_DBA_Tensione, ParameterDirection.Input);
            oparams[25] = new OracleParameter("TES_POTENZA_CONTR", OracleDbType.Decimal, r.Tes_DBA_Potenza_Contr, ParameterDirection.Input);
            oparams[26] = new OracleParameter("TES_POTENZA_TOLL", OracleDbType.Decimal, r.Tes_DBA_Potenza_Toll, ParameterDirection.Input);
            oparams[27] = new OracleParameter("TES_FASI", OracleDbType.Varchar2, r.Tes_DBA_Fasi, ParameterDirection.Input);
            oparams[28] = new OracleParameter("TES_USO", OracleDbType.Varchar2, r.Tes_DBA_Uso, ParameterDirection.Input);
            oparams[29] = new OracleParameter("TES_K", OracleDbType.Varchar2, r.Tes_DBA_K, ParameterDirection.Input); 
            oparams[30] = new OracleParameter("TES_NOTE", OracleDbType.Varchar2, r.Tes_Note, ParameterDirection.Input);
            oparams[31] = new OracleParameter("TES_DT_CHI_PRA", OracleDbType.TimeStamp, r.Tes_Dt_Chi_Pra, ParameterDirection.Input);
            oparams[32] = new OracleParameter("TES_DT_INV_PRA", OracleDbType.TimeStamp, r.Tes_Dt_Inv_Pra, ParameterDirection.Input); 
                       
            if (isInsert)
                oparams[33] = new OracleParameter("TES_COD_PRATICA", OracleDbType.Decimal, r.Id_tes_cod_pratica, ParameterDirection.Output);
            else
                oparams[33] = new OracleParameter("TES_COD_PRATICA", OracleDbType.Decimal, r.Id_tes_cod_pratica, ParameterDirection.Input);
            return oparams;
        }

        #region IDao<GEP_TESTATA,decimal> Members

        public Dictionary<decimal, GEP_TESTATA> GetAll()
        {
            throw new NotImplementedException();
        }

        public List<GEP_TESTATA> ricercaPratiche(string tipo, string ente, string codfis, string ragsoc, string numPrtASM, string numPrtDIS, string dta_iniArr, string dta_fineArr, string dta_iniIns, string dta_fineIns, int Stato, int uffAss, string dta_OraApp, string dta_AttoRich, string dta_IniSosp)
        {
            Oracle.DataAccess.Client.OracleCommand cmd;

            //string selectCount = "select count(*) from gep_testata";
            string selectCount = selectRicerca.Replace("f.*", "count(*)"); 
            bool firstParam1 = true;
            bool firstParam2 = true;
            string ct =" WHERE ";
            

            if (!string.IsNullOrEmpty(tipo) && tipo!=" ") {ct = ct + " TES_COD_SERVIZIO= '" + tipo + "' "; firstParam1 = false;}
            if (firstParam1 == false && !string.IsNullOrEmpty(ente) && ente != "NaN") ct = ct + " AND ";
            if (!string.IsNullOrEmpty(ente) && ente != "NaN") {ct = ct + "TES_COD_CONTR_DISP= '" + ente + "' "; firstParam1 = false;}
            if (firstParam1 == false && !string.IsNullOrEmpty(codfis)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(codfis)) {ct = ct + "(TES_CODFIS_CLI='" + codfis + "' OR TES_PARIVA_CLI='" + codfis + "')"; firstParam1 = false;}
            if (firstParam1 == false && !string.IsNullOrEmpty(ragsoc)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(ragsoc)) {ct = ct + "TES_POD= '" + ragsoc + "' "; firstParam1 = false;}
            if (firstParam1 == false && !string.IsNullOrEmpty(dta_iniArr)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(dta_iniArr)) { ct = ct + "TES_DT_ARR_PRA >= to_date('" + dta_iniArr + "','dd/mm/yyyy') "; firstParam1 = false; }
            if (firstParam1 == false && !string.IsNullOrEmpty(dta_fineArr)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(dta_fineArr)) { ct = ct + "TES_DT_ARR_PRA <= to_date('" + dta_fineArr + "','dd/mm/yyyy') "; firstParam1 = false; }
            
            if (firstParam1 == false && !string.IsNullOrEmpty(dta_iniIns)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(dta_iniIns)) { ct = ct + "TES_DT_INS_PRA >= to_date('" + dta_iniIns + "','dd/mm/yyyy') "; firstParam1 = false; }
            if (firstParam1 == false && !string.IsNullOrEmpty(dta_fineIns)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(dta_fineIns)) { ct = ct + "TES_DT_INS_PRA <= to_date('" + dta_fineIns + "','dd/mm/yyyy') "; firstParam1 = false; }

            if (firstParam1 == false && !string.IsNullOrEmpty(numPrtASM)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(numPrtASM)) { ct = ct + "TES_COD_PRATICA='" + numPrtASM + "' "; firstParam1 = false; }
            if (firstParam1 == false && !string.IsNullOrEmpty(numPrtDIS)) ct = ct + " AND ";
            if (!string.IsNullOrEmpty(numPrtDIS)) { ct = ct + "TES_COD_PRAT_UTENTE='" + numPrtDIS + "' "; firstParam1 = false; }
            if (firstParam1 == false && Stato>-1) ct = ct + " AND ";
            if (Stato > -1) { ct = ct + "TES_STATO = " + Stato; firstParam1 = false; }
            if (firstParam1 == false && uffAss > -1) ct = ct + " AND ";
            if (uffAss > -1) { ct = ct + "FAS_UNIT_OPER = " + uffAss; firstParam1 = false; }
            if (firstParam1 == false && (dta_OraApp !="" || dta_AttoRich !="" || dta_IniSosp !="")) ct = ct + " AND ";
            if (dta_OraApp != "" || dta_AttoRich != "" || dta_IniSosp != "")
            {
                firstParam1 = false;
                ct = ct + "TES_COD_PRATICA in (select FAS_COD_PRATICA FROM GEP_fase WHERE (FAS_STATO <98) and (";
                if (dta_OraApp != "" )
                {
                    firstParam2 = false;
                  ct=ct + "trunc(FAS_DTORA_APP) = to_date('" + dta_OraApp +"','dd/mm/yyyy')";
                }
                if (dta_AttoRich != "" )
                {
                    if (firstParam2 == false)
                    {
                        ct = ct + " OR ";
                    }
                    firstParam2 = false;
                    ct = ct + "FAS_DT_ATTO_RICH >= to_date('" + dta_AttoRich + "','dd/mm/yyyy')";
                }
                if (dta_IniSosp != "")
                {
                    if (firstParam2 == false)
                    {
                        ct = ct + " OR ";
                    }
                    firstParam2 = false;
                    ct = ct + "FAS_DT_INISOSP >= to_date('" + dta_IniSosp + "','dd/mm/yyyy')";
                }
                ct = ct + "))";
            }
            if (firstParam1)
            {
                cmd = new Oracle.DataAccess.Client.OracleCommand(selectCount , CurrentConnection);
            }
            else
            {
                cmd = new Oracle.DataAccess.Client.OracleCommand(selectCount + ct, CurrentConnection);
            }
            List<GEP_TESTATA> list = new List<GEP_TESTATA>();
            try
            {
                decimal count=(decimal)cmd.ExecuteScalar();
                if (count > 200) throw new Exception("La ricerca ha prodotto troppi risultati, applicare un filtro più stringente!!");
                if (firstParam1)
                {
                    cmd.CommandText = selectRicerca;
                }
                else
                {
                    cmd.CommandText = selectRicerca + ct;
                }
                cmd.CommandText = string.Concat(cmd.CommandText, " ORDER BY TES_COD_PRATICA DESC");
                using (OracleDataReader r = cmd.ExecuteReader())
                {
                    
                    if (r.HasRows)
                    {
                        
                        while (r.Read())
                        {
                            GEP_TESTATA t = DaoOracleDbHelper.MapTestataList(r);
                            list.Add(t);
                        }
                    }
                }
            }
            catch (Exception e0x)
            {
                throw new ManagedException("EX-FS003", e0x);
            }
            return list; 
        }

        public List<GEP_TESTATA> ricercaPraticheByStato(int Stato)
        {
            string selectCount = string.Concat("select count(*) from gep_testata WHERE TES_STATO = ", Stato);
            Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand(selectCount, CurrentConnection);
            List<GEP_TESTATA> list = new List<GEP_TESTATA>();
            try
            {
                decimal count = (decimal)cmd.ExecuteScalar();
                if (count > 200) throw new Exception("Non ci sono pratiche ");
                cmd.CommandText = string.Concat(selectRicerca," WHERE TES_STATO = ", Stato);
                using (OracleDataReader r = cmd.ExecuteReader())
                {

                    if (r.HasRows)
                    {

                        while (r.Read())
                        {
                            GEP_TESTATA t =DaoOracleDbHelper.MapTestataList(r);
                            list.Add(t);
                        }
                    }
                }
            }
            catch (Exception e0x)
            {
                throw new ManagedException("EX-FS003", e0x);
            }
            return list; 
        }
        
        public GEP_TESTATA GetById(decimal id)
        {
            Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand(selectById, CurrentConnection);
            cmd.Parameters.Add("TES_COD_PRATICA", id);
            GEP_TESTATA ut = null;
            try
            {
                using (OracleDataReader r = cmd.ExecuteReader())
                {
                    if (r.HasRows)
                        r.Read();
                    ut = DaoOracleDbHelper.MapTestata(r);
                    ut.Gep_risposta.Resp_Id = ut.Id_tes_cod_pratica;
                    if (!r.GetOracleClob(0).IsNull)
                    {
                        ut.Gep_risposta.Response = new System.Xml.XmlDocument();
                        ut.Gep_risposta.Response.LoadXml(r.GetOracleClob(0).Value);
                    }
                }
            }
            catch (Exception e0x)
            {
                throw new ManagedException("EX-TE002", e0x);
            }
            return ut;
        }

        public void Insert(GEP_TESTATA entity)
        {
            using (OracleCommand ocmd = new OracleCommand())
            {
                try
                {
                    ocmd.CommandText = insert;
                    ocmd.Parameters.AddRange(MappingParams(entity, true));
                    ocmd.Connection = base.CurrentConnection;
                    ocmd.ExecuteNonQuery();
                   
                    entity.Id_tes_cod_pratica = decimal.Parse(ocmd.Parameters["TES_COD_PRATICA"].Value.ToString());
                }
                catch (Exception e0x)
                {
                    throw new ManagedException("EX-PR004", e0x);
                }
            }
        }

        public void updateStatus(decimal id,int newStatus)
        {
            using (OracleCommand ocmd = new OracleCommand())
            {
                try
                {
                    if (newStatus == STATO_chiuso)
                        ocmd.CommandText = "UPDATE GEP_TESTATA SET TES_STATO =" + newStatus.ToString() + ", TES_DT_CHI_PRA = to_date('" + DateTime.Now.ToString("dd/MM/yyyy") + "','dd/mm/yyyy') WHERE TES_COD_PRATICA=" + id.ToString();
                    else
                    {
                        if (newStatus == STATO_inviata)
                            ocmd.CommandText = "UPDATE GEP_TESTATA SET TES_STATO =" + newStatus.ToString() + ", TES_DT_INV_PRA = to_date('" + DateTime.Now.ToString("dd/MM/yyyy") + "','dd/mm/yyyy') WHERE TES_COD_PRATICA=" + id.ToString();
                        else
                            ocmd.CommandText = "UPDATE GEP_TESTATA SET TES_STATO =" + newStatus.ToString() + " WHERE TES_COD_PRATICA=" + id.ToString();
                    }

                    
                    ocmd.Connection = base.CurrentConnection;
                    ocmd.ExecuteNonQuery();
                }
                catch (Exception e0x)
                {
                    throw new ManagedException("EX-PR009", e0x);
                }
            }
        }

        public void Update(GEP_TESTATA entity)
        {
            using (OracleCommand ocmd = new OracleCommand())
            {
                try
                {
                    ocmd.CommandText = update;
                    ocmd.Parameters.AddRange(MappingParams(entity, false));
                    ocmd.Connection = base.CurrentConnection;
                    ocmd.ExecuteNonQuery();

                    //entity.Id_tes_cod_pratica = decimal.Parse(ocmd.Parameters["TES_COD_PRATICA"].Value.ToString());
                }
                catch (Exception e0x)
                {
                    throw new ManagedException("EX-PR004", e0x);
                }
            }
        }

        public void Delete(decimal id)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}